package com.aat.high.orm;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.aat.high.orm.bean.User;
import com.aat.high.orm.dao.UserDaoSJImpl;
import com.aat.high.orm.dao2.UserDao2;

public class TestOrmMain {

	private static ClassPathXmlApplicationContext ctx;
	private static int Count = 1;

	public static void main(String[] args) {
		ctx = new ClassPathXmlApplicationContext("high-orm-spring.xml");

		long l1 = System.currentTimeMillis();
		testSpringJdbc(ctx);
		long l2 = System.currentTimeMillis();

		long l3 = System.currentTimeMillis();
		testSpringMybatis(ctx);
		long l4 = System.currentTimeMillis();
		
		long l5 = System.currentTimeMillis();
		
		long l6 = System.currentTimeMillis();

		System.out.println("Spring JDBC      : " + (l2 - l1));
		System.out.println("Spring Mybatis   : " + (l4 - l3));
		System.out.println("Spring hibernate : " + (l6 - l5));
		// {100:105,121},{1000:490,520},{10000:2500,3000}
		ctx.close();
	}

	private static void testSpringJdbc(ClassPathXmlApplicationContext ctx) {
		int i = 0;
		while (i < Count) {
			UserDaoSJImpl dao = ctx.getBean(UserDaoSJImpl.class);
			User u = dao.queryBean("1");
			int s =dao.queryAll().size();
			System.out.println(u+" "+s);
			i++;
		}
	}

	private static void testSpringMybatis(ClassPathXmlApplicationContext ctx) {
		int i = 0;
		while (i < Count) {
			UserDao2 dao = (UserDao2) ctx.getBean("userDao2");
			User u = dao.queryBean("1");
			int s =dao.queryAll().size();
			System.out.println(u+" "+s);
			i++;
		}
	}
	

}
